package com.gitee.wsl.data.input.strategy


import com.gitee.wsl.data.input.EventStrategyScope
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow

 class BufferedEventStrategy<Inputs : Any, Events : Any, State : Any> private constructor(
) : ChannelEventStrategy<Inputs, Events, State>(
    capacity = Channel.BUFFERED,
    onBufferOverflow = BufferOverflow.SUSPEND,
) {
     override suspend fun EventStrategyScope<Inputs, Events, State>.processEvents(
        eventsQueue: Flow<Events>,
    ) {
        eventsQueue
            .collect {
                dispatchEvent(it)
            }
    }

     companion object {
         operator fun invoke(): BufferedEventStrategy<Any, Any, Any> {
            return BufferedEventStrategy()
        }

         fun <Inputs : Any, Events : Any, State : Any> typed(): BufferedEventStrategy<Inputs, Events, State> {
            return BufferedEventStrategy()
        }
    }
}
